/*
 *
 *  Copyright (C) 2009 GSyC/LibreSoft
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *
 *  Author : Roberto Calvo Palomino <rocapal@gsyc.es>
 *
 */


package com.LibreGeoSocial.App;

import java.util.ArrayList;

import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.gesture.GestureLibrary;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;

import com.LibreGeoSocial.Api.GeoNode;

/**
 * This class implements a generic list to show the nodes of social network.
 * All the generic features are implemented in this class. 
 *
 * @author  Roberto Calvo
 * @version 11/11/2009	
 */



public class GenericList extends ListActivity {
	
	

	
	/** List of nodes that are shown.  */
	protected static ArrayList<GeoNode> mNodeList;
	
	/** ProgressDialog */
	private ProgressDialog mPDialog;
	
	private GestureLibrary mLibrary;
	
	//GeoNode where is save the node alarm
	protected GeoNode mNode;
	
	public void onCreate(Bundle savedInstanceState) {

		// Init
		super.onCreate(savedInstanceState);
		setContentView(R.layout.gesture_view);		 
		
		registerForContextMenu(this.getListView());
	}
	
	
	
	public void setList (ArrayList<GeoNode> list)
	{
		mNodeList = list;
	}
			
	
	@Override
	public void onCreateContextMenu(ContextMenu menu, View view,  ContextMenuInfo menuInfo)
	{ 
		
	}
	
	@Override
	public boolean onContextItemSelected(MenuItem item) 
	{
		
		return true;
	}
	
	
	/** This method show the progressDialog while an action is executed 
	 * 
	 *  @param title Title to progressDialog
	 *  @param description Description to progressDialog
	 *  @param th this thread is executed while progressDialog is shown.
	 * */
	protected void showProgressDialog (String title, String description, final Thread th)
	{		    	
    	
    	DialogInterface.OnCancelListener dialogCancel = new DialogInterface.OnCancelListener() {

            public void onCancel(DialogInterface dialog) {
            	
            	th.stop();
            }
          
        };
    	
        mPDialog = ProgressDialog.show(this, title, description, true, true, dialogCancel);		
		
        th.start();
		
	}
	
	protected Handler handler_PDialog = new Handler() {
		@Override
		public void handleMessage(Message msg) {			
			try{
				mPDialog.dismiss();	
			}catch(Exception e){
				Log.e("GenericList", "", e);
			}
		}
	};
	
	/* Thread */
	public void run() {
		
		handler_PDialog.sendEmptyMessage(0);
	}

}
